package com.telit.common.util;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;


/**
 * @author zhouyu
 * @description 行政区划工具类
 */
public class DistrictUtils {

    /**
     * 根据行政区划获取当前级别
     * @param districtCode
     * @return
     */
    public static String getAdminLevel(String districtCode){
        int length = districtCode.length();
        switch (length){
            case 0:
                return null;
            case 2:
                return "province";
            case 4:
                return "city";
            case 6:
                return "county";
            case 9:
                return "countryside";
            case 12:
                return "country";
        }
        return null;
    }

    /**
     * 获取最低级行政区划代码
     * @param districtCode
     * @return
     */
    public static String getLastAdminLevel(String districtCode){
        if (districtCode==null){
            return null;
        }
        int length = districtCode.length();
        switch (length){
            case 2:
                return districtCode;
            case 4:
                return districtCode.substring(2,4);
            case 6:
                return districtCode.substring(4,6);
            case 9:
                return districtCode.substring(6,9);
            case 12:
                return districtCode.substring(9,12);
            default:
                return null;
        }
    }

    /**
     *
     * @param districtMap
     * @param districtName
     * @return
     */
    public static boolean checkDistrictCode(Map<String,String> districtMap,String districtName){
        if(StringUtils.isEmpty(districtMap.get(districtName))){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println("021023".substring(4,6));
    }
}
